
package vn.aptech.project.model.dao;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import vn.aptech.project.model.dto.DBInfor;

public class CommonDAO {
private String connectionString;
private Statement statement;
private Connection con;

   public CommonDAO() throws ClassNotFoundException, SQLException, IOException {
        try {
                DBInfor info = new DBInfor();
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        connectionString = "jdbc:sqlserver://"+info.getServerName()+":"+info.getPort()+";databaseName="+info.getDatabaseName()+";user="+info.getUserName()+";password="+info.getPassword();
        connectionString = "jdbc:sqlserver://localhost:1433;databaseName=FurnitureSystem;user=sa;password=1234567";
        con = DriverManager.getConnection(connectionString);
        statement = con.createStatement();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

  }

public Vector ExecSelect(String strSelect) throws SQLException {
 ResultSet rs = statement.executeQuery(strSelect);
  Vector vtData = new Vector();
 while(rs.next())
  {
     Vector row = new Vector();
    for(int i=1;i<=rs.getMetaData().getColumnCount();i++)
     row.add(rs.getObject(i));
    vtData.add(row);
    }
   con.close();
    return vtData;
  }
public  int ExecNonQuery(String strNonQuery) throws SQLException
  {
      return statement.executeUpdate(strNonQuery);
   }

}
